package io.github.hadyang.leetcode.offer;

import io.github.hadyang.leetcode.ListNode;
import org.junit.Test;

/** @author haoyang.shi */
public class O1DeleteNode {

  @Test
  public void test() {}

  public void O1DeleteNode(ListNode head, ListNode needDelete) {

    if (needDelete.next != null) {
      ListNode next = needDelete.next.next;
      needDelete.val = needDelete.next.val;
      needDelete.next = next;

    } else {
      ListNode cursor = head;

      while (cursor != null) {
        if (cursor.next == needDelete) break;

        cursor = cursor.next;
      }

      if (cursor == null) return;

      cursor.next = needDelete.next;
    }
  }
}
